package firstStage.part9;

/**
 * @ClassName: [StringBuilderDemo1]
 * @Description: StringBuilder和String相互转换
 * @Author: [黄劲松]
 * @CreateDate: [2021-02-07]
 * @Version: [v1.0]
 */
/*
StringBuilder和String相互转换
    1. StringBuilder转换为String
    public String toString():通过toString()就可以实现把StringBuilder转换为String
    2. String转换为StringBuilder
    public StringBuilder(Strings):通过构造方法就可以实现把String转换为StringBuilder
*/
public class StringBuilderDemo1 {
    public static void main(String[] args) {
        //1. StringBuilder转换为String
        StringBuilder sb = new StringBuilder();
        sb.append("hello");
        //String s = sb;     //错误的做法
        String s = sb.toString();
        System.out.println(s);
        //2. String转换为StringBuilder
        String s1 = "world";
        //StringBuilder sb1=s1;  //错误的做法
        StringBuilder sb1 = new StringBuilder(s1);
        System.out.println(sb1);
    }
}